package com.hospital.controller;

import com.alibaba.excel.EasyExcel;
import com.hospital.dto.EqucheckDto;
import com.hospital.dto.EquipmentDto;
import com.hospital.entity.Equcheck;
import com.hospital.entity.Equipment;
import com.hospital.service.intf.EqucheckService;
import com.hospital.util.SessionUtil;
import com.hospital.vo.PageBean;
import com.hospital.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/equcheck/")
public class EqucheckController {
    @Autowired
    private EqucheckService service;

    @PostMapping("add.do")
    public R add(Equcheck equcheck){
        return service.add(equcheck);
    }

    @GetMapping("page.do")
    public PageBean selectPage(String name, String ctime,int page, int limit){
        System.out.println(name+"-------------"+ctime);
//        return service.selectPage(name,ctime,page,limit);
        return new PageBean();
    }
    @GetMapping("time.do")
    public R seletime(Date ctime){
        return service.seletime(ctime);
    }

    @GetMapping("download.do")
    public void download(HttpServletResponse response) throws IOException {
        //1.设置 响应消息头 下载
        response.setHeader("content-disposition","attachment;filename=equcheckdto-"+System.currentTimeMillis()+".xlsx");
        //2.查询学员数据
        List<EqucheckDto> list=service.all1();
        //3.实现数据写出 Excel生成
        EasyExcel.write(response.getOutputStream(), EqucheckDto.class).sheet(System.currentTimeMillis()+"").doWrite(list);
    }

    @PostMapping("deleids.do")
    public R deleids(int[] ids){
        return service.deleids(ids);
    }

    //分页查询症状
    @GetMapping("pagechecklog.do")
    public PageBean pageChecklog(int page, int limit, String name){
        return service.checkLog(name, page, limit);
    }

}
